<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.util.ArrayList,com.jspsmart.upload.*, kines.ct.*"%>
<jsp:useBean id="bean_upload_file" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%@include file="../utils/validarSession.jsp" %>
<%
boolean uploadedFile = false;
String fileName = "";
bean_upload_file.initialize(pageContext);
Request requestUp = bean_upload_file.getRequest();
try{
	bean_upload_file.upload();

	requestUp = bean_upload_file.getRequest();

/*	if( !bean_upload_file.getFiles().getFile(0).isMissing() ){
		java.io.File myFile = new java.io.File(application.getRealPath("/")+"\\tmp\\"+bean_upload_file.getFiles().getFile(0).getFileName());
		if( myFile.exists() )myFile.delete();
	}
*/
	if (!bean_upload_file.getFiles().getFile(0).isMissing()){
		java.io.File myDir = new java.io.File(application.getRealPath("/")+"\\tmp\\");
		if( !myDir.exists() )myDir.mkdir();
		fileName = bean_upload_file.getFiles().getFile(0).getFileName();
		bean_upload_file.save( "tmp/" );
		uploadedFile = true;
	}
}catch( NegativeArraySizeException upE ){
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Subir prospectos desde excel</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../css/arastyle.css" type="text/css">
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>
<script src="../utils/tooltip.js"language="JavaScript1.2"></script>
</head>

<body class="fondo">
<%
	if( !uploadedFile ){
%>
<form action="" method="post" enctype="multipart/form-data" name="SubirProspectos"><br>
<br>
<br>
<table width="90%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr class="titulos">
    <th height="20" colspan="2" scope="col">Subir Eventos desde Archivo de Excel </th>
  </tr>
  <tr>
    <td height="25" width="30%" class="etiqueta"><div align="right"><strong>Archivo:</strong></div></td>
    <td height="25" width="70%" bgcolor="#FFFFFF"><input name="archivoExcel" type="file" class="textfields"></td>
  </tr>
   <tr>
    <td height="25" colspan="2" bgcolor="#FFFFFF"><div align="center">
      <input onClick="window.close()" name="Button" type="button" class="boton" value="Cerrar Ventana">
      &nbsp;
      <input name="Submit2" type="submit" class="boton" value="Aceptar">
    </div></td>
  </tr>
</table>
</form>
<%
	}else{
		out.println("<script>");
		out.println("window.moveTo((screen.width - 800) / 2, (screen.height - 600) / 2);");
		out.println("window.resizeTo(800,600);");
		out.println("window.opener.location.reload();");
		out.println("</script>");
		%>
		<table width="100%"  border="0" cellspacing="0" cellpadding="0">
		  <tr class="titcolumna">
			<td width="35%"><div align="center">Prospecto</div></td>
			<td width="10%"><div align="center">Fracc</div></td>
			<td width="20%"><div align="center">Evento</div></td>
			<td width="30%"><div align="center">Comentarios</div></td>
		    <td width="5%"><div align="center">Res</div></td>
		  </tr>
		</table>
		<%
		Object [] eventosRes = Event.getDataExcel( application.getRealPath("/")+"tmp\\"+fileName, session );
		if( eventosRes != null){
			ArrayList eventos = (ArrayList)eventosRes[0];
			ArrayList errors = (ArrayList)eventosRes[1];
			for( int i = 0; i < eventos.size(); i++ ){
				Event evento = (Event)eventos.get(i);
				EventType tipoEvento = evento.getEventType();
				String error = (String)errors.get(i);
				%>
				<table width="100%"  border="1" cellpadding="0" cellspacing="0">
				  <tr class="etiqueta">
					<td width="35%"><div align="center"><%=Prospect.getData( evento.getProspectId( ) ).getCompleteName()%></div></td>
					<td width="10%" onMouseOver="showtip(this,event,'<%=Development.getData( evento.getDevelopmentCode() ).getName()%>')" onMouseOut="hidetip();"><div align="center"><%=evento.getDevelopmentCode()%></div></td>
					<td width="20%"><div align="center"><%=tipoEvento!=null?tipoEvento.getDescription():"&nbsp;"%></div></td>
					<td width="30%"><div align="center"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0">
  <tr>
    <th scope="col"><strong>&nbsp;<%=evento.getRemarks()%></strong></th>
  </tr>
</table>
</div></td>
				    <td width="5%" onMouseOver="showtip(this,event,'<%=error%>')" onMouseOut="hidetip();"><div align="center"><img src=<%=error.equals("")?"../images/palomita.gif":"../images/cross_red.gif"%> width="16" height="16"></div></td>
				  </tr>
</table>
				  <%
			}
		}else{
			out.println( session.getAttribute("mensaje") );
		}
		java.io.File myFile = new java.io.File(application.getRealPath("/")+"\\tmp\\"+bean_upload_file.getFiles().getFile(0).getFileName());
		if( myFile.exists() )myFile.delete();
%>
<br><div align="center"><a href="#" onClick="window.close();">Cerrar Ventana</a>  </div>
<%
	}
%>
</body>
</html>